<?php 

// 用户控制器
class UserController extends Controller
{
    public function index()
    {
        $data = DB::table('user')->order('id desc')->select();
        // var_dump($data);
        $this->assign('title', '用户列表');
        $this->assign('list', $data);
        $this->display('User/index.html');
    }

    public function del()
    {
        if (DB::table('user')->delete($_GET['id'])) {
            $this->redirect('恭喜您,删除成功o(≧v≦)o~~好棒~', './index.php?c=User');
        } else {
            $this->redirect('删除失败(ノ°ο°)ノ高能预警 ', './index.php?c=User');
        }
    }

    // 加载表单
    public function add()
    {
        $this->assign('title', '添加用户');
        $this->display('User/add.html');
    }
    // 执行添加
    public function insert()
    {
        if (DB::table('user')->insert() > 0) {
            $this->redirect('恭喜您,添加成功o(≧v≦)o~~好棒~', './index.php?c=User');
        } else {
            $this->redirect('添加失败(ノ°ο°)ノ高能预警 ');
        }
    }

    public function edit()
    {
        $data = DB::table('user')->find($_GET['id']);
        // var_dump($data);
        $this->assign('title', '编辑用户');
        $this->assign('data', $data);
        $this->display('User/edit.html');
    }

    public function update()
    {
        if (DB::table('user')->update()) {
            $this->redirect('恭喜您,编辑成功o(≧v≦)o~~好棒~', './index.php?c=User');
        } else {
            $this->redirect('编辑失败(ノ°ο°)ノ高能预警 ');
        }
    }
}



